<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 서비스 관리 컨트롤러
 */
class Service extends CI_Controller {

	var $data = array();
	
	function __construct() {
		parent::__construct();
		$this->data['category']['main'] = $this->uri->segment(1);
		$this->data['category']['sub']  = $this->uri->segment(2);
	}

	// Default
	function index() {
		$this->service_list();
	}

	/**
	 * 운세 서비스 리스트
	 */
	function service_list() {
		log_message('debug', "@@@@ Service::service_list()");

		// DB 연동 처리
		$this->load->model('admin/Service_model', 'model', TRUE);
		$this->data['service_list'] = $this->model->select_service_list();
		$this->data['package_list'] = $this->model->select_package_list();
		
		// 뷰로 이동
		$this->load->view('admin/service_list_v', $this->data);
	}

	/**
	 * 운세 서비스 업데이트
	 * 전체 다 한꺼번에 업데이트 한다.
	 */
	function update() {
		log_message('debug', "@@@@ Service::update()");
		
		// 폼 입력값 가져오기
		$arr_idx              = $this->input->post('idx');
		$arr_service_group_id = $this->input->post('service_group_id');
		$arr_service_id       = $this->input->post('service_id');
		$arr_service_name     = $this->input->post('service_name');
		$arr_package_cd       = $this->input->post('package_cd');
		$arr_price            = $this->input->post('price');
		$arr_price_vat        = $this->input->post('price_vat');
		$arr_service_url      = $this->input->post('service_url');		

		// DB 연동 처리
		$this->load->model('admin/Service_model', 'model', TRUE);
		$cnt = count($arr_idx);
		for ($i=0; $i < $cnt; $i++) {
			$service = array(
				'idx'              => $arr_idx[$i],
				'service_group_id' => $arr_service_group_id[$i],
				'service_id'       => $arr_service_id[$i],
				'service_name'     => $arr_service_name[$i],
				'package_cd'       => $arr_package_cd[$i],
				'price'            => $arr_price[$i],
				'price_vat'        => $arr_price_vat[$i],
				'service_url'      => $arr_service_url[$i]
			); 
			$this->model->update_service($service);			
		}
		
		// 뷰로 이동
		redirect('/admin/service', 'refresh');
	}

	/**
	 * 운세 서비스 등록
	 */
	function insert() {
		log_message('debug', "@@@@ Service::insert()");
		
		// 폼 입력값 가져오기
		$service['idx']              = $this->input->post('idx', TRUE);
		$service['service_group_id'] = $this->input->post('service_group_id', TRUE);
		$service['service_id']       = $this->input->post('service_id', TRUE);
		$service['service_name']     = $this->input->post('service_name', TRUE);
		$service['package_cd']       = $this->input->post('package_cd', TRUE);
		$service['price']            = $this->input->post('price', TRUE);
		$service['price_vat']        = $this->input->post('price_vat', TRUE);
		$service['service_url']      = $this->input->post('service_url', TRUE);		

		// DB 연동 처리
		$this->load->model('admin/Service_model', 'model', TRUE);
		$this->model->insert_service($service);			
		
		// 뷰로 이동
		redirect('/admin/service', 'refresh');
	}

}

/* End of file service.php */
/* Location: ./application/controllers/admin/service.php */